//
//  TWAnimatedTransition.m
//  图片浏览
//
//  Created by 谭伟 on 2017/4/27.
//  Copyright © 2017年 迷你金服. All rights reserved.
//

#import "TWAnimatedTransition.h"

@implementation TWAnimatedTransition
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 1;
}

// 在这个方法中实现转场动画 ：modal和dismis都调用这个方法
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    if (self.presented) {
        UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
        
        toView.alpha = 0;
        
        [UIView animateWithDuration:0.5 animations:^{
            
            toView.alpha = 1;
            
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
    } else {
        UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
        [UIView animateWithDuration:0.5 animations:^{
            
            fromView.alpha = 0;
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
        
    }
}

@end
